﻿using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Data;

namespace IsConveter {
    /// <summary>与えられた値がboolのtrueかどうかを判別し、対応した値に変換するコンバーターです</summary>
    public class IsTrueConverter : DependencyObject, IValueConverter {

        #region Property
        /// <summary>条件が成立した時の値 </summary>
        public object IsValue {
            get { return (object)GetValue(IsValueProperty); }
            set { SetValue(IsValueProperty, value); }
        }

        // Using a DependencyProperty as the backing store for IsValue.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty IsValueProperty =
            DependencyProperty.Register("IsValue", typeof(object), typeof(IsTrueConverter), new PropertyMetadata(false));


        /// <summary>条件が成立しなかったときに返す値 </summary>
        public object NotValue {
            get { return (object)GetValue(NotValueProperty); }
            set { SetValue(NotValueProperty, value); }
        }

        // Using a DependencyProperty as the backing store for NotValue.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty NotValueProperty =
            DependencyProperty.Register("NotValue", typeof(object), typeof(IsTrueConverter), new PropertyMetadata(true));
        #endregion

        #region IValueConverter メンバー
        /// <summary>与えられた値がboolのtrue値かどうかを判別し、対応した値に変換します</summary>
        /// <param name="value">判別値</param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="language"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, string language) {
            return value is bool && (bool)value ? IsValue : NotValue;
        }
        /// <summary>実装しません。常にNotImplementedException/// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="language"></param>
        /// <returns></returns>
        public object ConvertBack(object value, Type targetType, object parameter, string language) {
            throw new NotImplementedException();
        }

        #endregion
    }
}
